package com.storage.joyce.storageapp.util;

import android.app.Activity;

import java.util.LinkedList;
import java.util.List;

public class ActivityUtil {

    private static List<Activity> activityList = new LinkedList<Activity>();
    private static ActivityUtil instance;

    private ActivityUtil() {
    }

    public static Activity getActivityContext() {
        for(int i = 0; i<activityList.size();i++){
            Tools.loge("或得到的activity是里："+activityList.get(i));
        }
        return activityList.get(activityList.size()-1);
    }

    public static List<Activity> getActivityList() {
        return activityList;
    }

    public void removeActivity(Activity activity){
        for(int i=0;i<activityList.size();i++){
            if (activity==activityList.get(i)){
                activityList.remove(i);
                return;
            }
        }
    }

    // 单例模式中获取唯一的ExitUtil实例
    public static ActivityUtil getInstance() {
        if (null == instance) {
            instance = new ActivityUtil();
        }
        return instance;

    }

    // 添加Activity到容器中
    public void addActivity(Activity activity) {
        activityList.add(activity);
    }

    // 遍历所有Activity并finish

    public void exit() {

        for (Activity activity : activityList) {
            activity.finish();
        }

        System.exit(0);

    }
}
